package ihm_clarifiee.Presentation;



import ihm_clarifiee.Control.CProjet;
import ihm_clarifiee.Presentation.model_table.model_table_listeEquipe;
import ihm_clarifiee.Presentation.model_table.model_table_listeRelease;
import ihm_clarifiee.Presentation.model_table.model_table_listeUtilisateurs;
import ihm_clarifiee.Control.CEquipe;
import ihm_clarifiee.Control.CRelease;
import ihm_clarifiee.Control.CSprint;
import ihm_clarifiee.Presentation.model_table.model_table_allsprints;
import ihm_clarifiee.Presentation.popup.DetailSprint;
import ihm_clarifiee.Presentation.popup.Detail_utilisateur;
import ihm_clarifiee.Presentation.popup.base_affichage;
import ihm_clarifiee.Presentation.popup.popup;
import ihm_clarifiee.Presentation.popup.popup_release;
import ihm_clarifiee.application.Projet;
import ihm_clarifiee.application.Release;
import ihm_clarifiee.application.Sprint;
import ihm_clarifiee.application.Usine;
import ihm_clarifiee.application.Utilisateur;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import javax.swing.JOptionPane;

import javax.swing.JPanel;
import sun.awt.VerticalBagLayout;

public class PEquipe extends javax.swing.JPanel implements popup {
	
	 private model_table_listeUtilisateurs mdu;
     private model_table_listeEquipe mde;
     private CEquipe  controleEquipe;
     private PListeEquipe ptestEquipe;
    
    
    public PEquipe(CEquipe c) {
//   	 System.out.println("PRelease.java");
   	    controleEquipe =c;
        initComponents();
        mdu=new model_table_listeUtilisateurs();
        mde=new model_table_listeEquipe();
        tbl_principal.setModel(mde);
        //**//
       // tbl_active.setModel(mde);
        initModel();
        updateliste();
    }
    
    public void setListe(PListeEquipe pdt){
    	ptestEquipe=pdt;
    }

     /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
      * always regenerated by the Form Editor.
      */
     private void initModel ()
     {
         tbl_principal.getColumnModel().getColumn(0).setMinWidth(100);
         tbl_principal.getColumnModel().getColumn(0).setPreferredWidth(100);
         tbl_principal.getColumnModel().getColumn(0).setMaxWidth(100);
         tbl_principal.getColumnModel().getColumn(1).setMinWidth(10);
         tbl_principal.getColumnModel().getColumn(1).setPreferredWidth(50);
         tbl_principal.getColumnModel().getColumn(1).setMaxWidth(50);
         tbl_principal.getColumnModel().getColumn(2).setMinWidth(80);
         tbl_principal.getColumnModel().getColumn(2).setPreferredWidth(150);
         tbl_principal.getColumnModel().getColumn(2).setMaxWidth(150);
         tbl_principal.getColumnModel().getColumn(3).setMinWidth(80);
         tbl_principal.getColumnModel().getColumn(3).setPreferredWidth(150);
         tbl_principal.getColumnModel().getColumn(3).setMaxWidth(150);
         tbl_principal.getColumnModel().getColumn(4).setMinWidth(100);
         tbl_principal.getColumnModel().getColumn(4).setPreferredWidth(300);
         tbl_principal.getColumnModel().getColumn(4).setMaxWidth(4000);
         tbl_principal.getColumnModel().getColumn(0).setResizable(true);
         tbl_principal.getColumnModel().getColumn(1).setResizable(true);
         tbl_principal.getColumnModel().getColumn(2).setResizable(true);
         tbl_principal.getColumnModel().getColumn(3).setResizable(true);
          tbl_principal.getColumnModel().getColumn(4).setResizable(true);
         tbl_principal.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
/*
        tbl_active.getColumnModel().getColumn(0).setMinWidth(20);
        tbl_active.getColumnModel().getColumn(0).setPreferredWidth(100);
        tbl_active.getColumnModel().getColumn(0).setMaxWidth(2000);
        tbl_active.getColumnModel().getColumn(1).setMinWidth(30);
        tbl_active.getColumnModel().getColumn(1).setPreferredWidth(300);
        tbl_active.getColumnModel().getColumn(1).setMaxWidth(4500);
        tbl_active.getColumnModel().getColumn(2).setMinWidth(100);
        tbl_active.getColumnModel().getColumn(2).setPreferredWidth(150);
        tbl_active.getColumnModel().getColumn(2).setMaxWidth(4000);
        tbl_active.getColumnModel().getColumn(3).setMinWidth(100);
        tbl_active.getColumnModel().getColumn(3).setPreferredWidth(150);
        tbl_active.getColumnModel().getColumn(3).setMaxWidth(4000);
        tbl_active.getColumnModel().getColumn(0).setResizable(true);
        tbl_active.getColumnModel().getColumn(1).setResizable(true);
        tbl_active.getColumnModel().getColumn(2).setResizable(true);
        tbl_active.getColumnModel().getColumn(3).setResizable(true);
        tbl_active.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);

*/

      }


     private void initComponents() {

         panelVertical = new JPanel();
         jScrollPane1 = new javax.swing.JScrollPane();
         jScrollPane2 = new javax.swing.JScrollPane();
         tbl_principal = new javax.swing.JTable();
         //tbl_active = new javax.swing.JTable();
         bt_ajouter = new javax.swing.JButton();
         bt_suppr = new javax.swing.JButton();
         bt_modifier = new javax.swing.JButton();
         bt_monter = new javax.swing.JButton();
         bt_descendre = new javax.swing.JButton();
         bt_detail = new javax.swing.JButton();
         jLabel1 = new javax.swing.JLabel();
         jLabel2 = new javax.swing.JLabel();


         jScrollPane1.setViewportView(tbl_principal);
         //jScrollPane2.setViewportView(tbl_active);


         bt_ajouter.setText("Ajouter");
         bt_ajouter.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 bt_ajouterActionPerformed(evt);
             }
         });

         bt_suppr.setText("Suppr");

           bt_suppr.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 bt_supprActionPerformed(evt);
             }
         });


         bt_modifier.setText("Modifier");
           bt_monter.setText("Monter");
             bt_descendre.setText("Descendre");

         bt_detail.setText("Detail");

           bt_detail.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 bt_detailActionPerformed(evt);
             }
         });
             bt_modifier.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
                 bt_modifierActionPerformed(evt);
             }
         });

         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
         jLabel1.setText("Liste des Sprints");
         jLabel1.setMaximumSize(new java.awt.Dimension(146, 124));

         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18));
         jLabel2.setText("Release associee");
         jLabel2.setMaximumSize(new java.awt.Dimension(146, 124));



         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                             .addComponent(bt_suppr, 98, 98,98)
                             .addComponent(bt_ajouter, 98, 98, 98)
                             .addComponent(bt_modifier, 98, 98, 98)
                             .addComponent(bt_detail, 98, 98, 98)
                              .addComponent(bt_monter, 98, 98, 98)
                             .addComponent(bt_descendre, 98, 98, 98)))
                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
                 .addContainerGap())
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addGap(9, 9, 9)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                     .addGroup(layout.createSequentialGroup()
                         .addComponent(bt_ajouter)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(bt_modifier)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(bt_suppr)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(bt_detail)
                         .addGap(23, 23, 23)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(bt_monter)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                         .addComponent(bt_descendre)
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                          .addGap(123, 123, 123))
                     .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE))
                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                     .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addGap(9, 9, 9)
                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                     .addComponent(jScrollPane2, 35,35, Short.MAX_VALUE)
                 .addContainerGap())
         );

     }

     private void bt_ajouterActionPerformed(java.awt.event.ActionEvent evt) {
       //  String [] t ={"nom","objectif","date debut","date fin"};
       //  md.add(t);
       //  tbl_principal.repaint();
      /*   popup_release popup = new popup_release(Release);
         base_affichage ba = new base_affichage(popup);
         ba.getMainPanel().setLayout(new VerticalBagLayout());
         ba.getMainPanel().add(popup);
         ba.setVisible(true);*/
     }



       private void bt_supprActionPerformed(java.awt.event.ActionEvent evt) {
       int sel = ligneSelectionnee();
       int n = JOptionPane.showConfirmDialog(null,"Voulez-vous vraiment supprimer ce sprint","Confirmation",JOptionPane.YES_NO_OPTION);
       if(n==JOptionPane.YES_OPTION)
       {

       controleEquipe.getM_listeUtilisateurs().remove(sel);
           }
      updateliste();
       tbl_principal.repaint();
     }




    public void updateliste()
     {
    	
     mdu.removeAll();
    Iterator it = controleEquipe.getM_listeUtilisateurs().iterator();
     Sprint rl;
    while(it.hasNext())
    {
    rl =(Sprint)it.next();
    Integer i= new Integer(rl.getDuree());
    String [] t ={rl.getNom(),i.toString(),rl.getDateDebut().toString(),rl.getDateFin().toString(),rl.getObjectifs()};
     mdu.add(t);

    }
     //mda.removeAll();
     

      String [] v ={controleEquipe.getNom(),controleEquipe.getScumMaster().getNom(),controleEquipe.getDescription()};
    // mda.add(v);
         
 //  System.out.println("update ");
     this.repaint();
     tbl_principal.repaint();
     if( controleEquipe.getPEquipe()!=null)
     controleEquipe.getPEquipe().repaint();
     }

    

     private void bt_detailActionPerformed(java.awt.event.ActionEvent evt) {
       int sel = ligneSelectionnee();
       Detail_utilisateur frame_detailSprint = new Detail_utilisateur(controleEquipe.getM_listeUtilisateurs().get(sel),controleEquipe.getProjet().getBacklog());
       frame_detailSprint.setVisible(true);
     //CSprint s= (CSprint)(controle.getM_listeSprint().get(sel));
         // popup_release popup = new popup_release(projet);
       /*  base_affichage ba = new base_affichage(s.getPresentation());
         ba.getMainPanel().setLayout(new VerticalBagLayout());
         ba.getMainPanel().add(s.getPresentation());
         ba.setVisible(true);*/
     }

      private void bt_modifierActionPerformed(java.awt.event.ActionEvent evt) {
      /*   int sel = ligneSelectionnee();
           CRelease r= (CRelease)(Release.getListeRelease().get(sel));
         popup_release popup = new popup_release(Release,r);
         base_affichage ba = new base_affichage(popup);
         ba.getMainPanel().setLayout(new VerticalBagLayout());
         ba.getMainPanel().add(popup);
         ba.setVisible(true);*/

     }
       public javax.swing.JTable getTable()
       {
           return  tbl_principal;
       }
     public int ligneSelectionnee(){
         return tbl_principal.getSelectedRow();
     }

     public void update(int sel){
      /*
         ((model_table_backlog)(tbl_principal.getModel())).update(sel, ((CBacklog)controle).getHistoire(sel).getNom(), ((CBacklog)controle).getHistoire(sel).getDescription(), ((CBacklog)controle).getHistoire(sel).getDuree(),((CBacklog)controle).getHistoire(sel)getTaches());
         tbl_principal.repaint();*/
     }

  /*  public void updateAffichage(){
     	md.removeAll();
     	int i = Release.getListeRelease().size();
     	while (i>0){
     		i--;
 			Release r = Release.getListeRelease().get(i);
     		String[] t = {r.getNom(), r.getObjectif(), String.valueOf(r.getDateDebut()), String.valueOf(r.getDateFin())};
     		md.add(t);
     		tbl_principal.repaint();
     	}
     	tbl_principal.repaint();
     }*/



     // Variables declaration - do not modify
     private JPanel panelVertical;
     private javax.swing.JButton bt_ajouter;
     private javax.swing.JButton bt_detail;
     private javax.swing.JButton bt_modifier;
     private javax.swing.JButton bt_suppr;

     private javax.swing.JButton bt_monter;
     private javax.swing.JButton bt_descendre;

     private javax.swing.JLabel jLabel1;
     private javax.swing.JLabel jLabel2;
     private javax.swing.JScrollPane jScrollPane1;
     private javax.swing.JScrollPane jScrollPane2;
     private javax.swing.JTable tbl_principal;
     // End of variables declaration


     public boolean valider() {
     	return true;
     }
}

